package com.vegas.netspider.core;

import java.util.Date;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleTrigger;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;

import com.vegas.netspider.ApplicationContext;

public class NetSpiderController {
	
	private ApplicationContext context;

	public void closeOn(long start,long end) throws SchedulerException{
		Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
		
		Trigger tri = new SimpleTrigger("close_net_spider",new Date(start-10000L));
		JobDetail job = new JobDetail("close_net_spider", ShutdownNetSpider.class);
		scheduler.scheduleJob(job, tri);
		
		Trigger tri2 = new SimpleTrigger("open_net_spider",new Date(end+10000L));
		JobDetail job2 = new JobDetail("open_net_spider", BootNewSpider.class);
		scheduler.scheduleJob(job2, tri2);
		
		scheduler.getContext().put(ApplicationContext.appContextBeanName, context);
		
		scheduler.start();
		
	}

	public void setContext(ApplicationContext context) {
		this.context = context;
	}
	
	
}
